package com.bsj.pay.util.platform.wsgw.sm;


import org.bouncycastle.crypto.params.*;
import org.bouncycastle.math.ec.*;
import org.bouncycastle.crypto.*;
import java.math.*;

public class SM2GenUtils
{
    private static final int BYTE_LENGTH = 32;
    
    public static String[] generateKeyPair() {
        final SM2 instance = SM2.Instance();
        ECPoint q = null;
        final byte[] array = new byte[32];
        final byte[] array2 = new byte[32];
        for (int i = 0; i < 10; ++i) {
            final AsymmetricCipherKeyPair generateKeyPair = instance.ecc_key_pair_generator.generateKeyPair();
            final ECPrivateKeyParameters ecPrivateKeyParameters = (ECPrivateKeyParameters)generateKeyPair.getPrivate();
            final ECPublicKeyParameters ecPublicKeyParameters = (ECPublicKeyParameters)generateKeyPair.getPublic();
            final BigInteger d = ecPrivateKeyParameters.getD();
            q = ecPublicKeyParameters.getQ();
            final byte[] byteArray = d.toByteArray();
            if (!Util.byteToHex(byteArray).equals(Util.byteToHex(array2)) && byteArray.length == 32) {
                System.arraycopy(byteArray, 0, array, 0, 32);
                break;
            }
        }
        return new String[] { Util.byteToHex(q.getEncoded()), Util.byteToHex(array) };
    }
}

